<?php
namespace app\home\model;

use think\Db;

class OrderModel  
{
    /**
     * 单例模式
     * @return OrderModel
     *
     */
    public static function instance(){
        static $m = null;
        if(!$m){
            $m = new OrderModel();
        }
        return $m;
    }
    /**
     * 订单
     */
    public function orderlist($bid,$status,$order){
        $result = Db::name('goodsOrder')->alias('g')->join('135k_user u','g.uid = u.uid')
            ->field('g.orderid,g.uid,g.order_no,g.bid,g.num,g.money,g.sendtime,g.taketime,g.pay_way,g.status,g.createtime,g.paytime,g.remark,u.nickname,u.phone')
            ->where(['g.bid'=>$bid,'g.status'=>$status])
            ->order($order)
            ->paginate(10);
        return $result;
    }
    /**
     * 详情
     */
    public function showlist($id){
        $goodsorder =  Db::name('goodsOrder')
            ->alias('g')
            ->join('135k_user u','g.uid = u.uid')
            ->field('g.orderid,g.uid,g.order_no,g.bid,g.num,g.money,g.address,g.taketime,g.sendtime,g.pay_way,g.status,g.name as cname,g.phone as cphone,
            g.createtime,g.paytime,g.remark,u.nickname,u.phone,g.express_number,g.exid')
            ->where('orderid',$id)
            ->find();
        if($goodsorder['exid'] != 0){
            $express =  Db::name('express')
                ->field('name')
                ->where('exid',$goodsorder['exid'])
                ->find();
            $goodsorder['exname'] = $express['name'];
        }else{
            $goodsorder['exname'] = '';
        }

        $goodsorder['goods'] = Db::name('orderGoods')->alias('o')
            ->join('135k_goods s','s.goodsid = o.goodsid')
            ->field('o.goodsid,o.num,o.rule,o.rule1,o.rule2,o.price,o.total_price,s.name as gname')
            ->where('o.orderid',$goodsorder['orderid'])
            ->select();

        //print_r($result);exit;
        return $goodsorder;
    }
    /**
     * 添加快递
     */
    public function addexpress($data){
        $result = Db::name('goodsOrder')->where('orderid',$data['pid'])->update(['status'=>3,'express_number'=>$data['number'],'exid'=>$data['mun']]);
        return $result;
    }



}
